package com.huiquan.onlineTime.job;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.huiquan.onlineTime.dao.OnlineTimeDailyDao;
import com.huiquan.onlineTime.service.OnlineTimeRecordService;

@Component
public class OnlineTimeJob {
    private static final Logger LOG = LoggerFactory.getLogger(OnlineTimeJob.class);

	@Autowired
	private OnlineTimeRecordService onlineTimeRecordService;
	
	@Autowired
	private OnlineTimeDailyDao onlineTimeDailyDao;
	
    /**
     * 每5分钟执行一次，将内存中的记录更新一遍
     */
//    @Scheduled(cron="0 0/5 * * * ? ")
	@Scheduled(cron="0 0/5 6-23 * * ? ")
    public void resetRecord() {
    	LOG.debug("resetRecord start");
    	onlineTimeRecordService.resetAll(new Date());
    	LOG.debug("resetRecord end");
    }
    
    /**
     * 每天4点执行，统计日报表
     */
    @Scheduled(cron="0 0 4 * * ? ")
    public void calculateDaily() {
    	LOG.info("calculateDaily begin");
    	onlineTimeDailyDao.calculateDaily();
    	LOG.info("calculateDaily end");
    }
}
